lib: fix clippy
authorFelix Krull <f_krull@gmx.de>
Wed, 12 Jun 2019 22:51:38 +0000 (00:51 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:54 +0000 (12:53 -0400)
Look, the type is fine. It's only an opaque thing to ensure lifetimes
anyway.

rust-bindings/rust/src/repo_checkout_at_options.rs
rust-bindings/rust/src/repo_checkout_at_options/repo_checkout_filter.rs

index 0ebf7be73e9554e590efd68be3460a8bea77a6be..4b49e2c63786d618667d4cb1a82536ccc0929917 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{RepoCheckoutMode, RepoCheckoutOverwriteMode, RepoDevInoCache, SePolicy};
-use glib::translate::{Stash, ToGlib, ToGlibPtr};
+use glib::translate::*;
 use libc::c_char;
-use ostree_sys::{OstreeRepoCheckoutAtOptions, OstreeRepoDevInoCache, OstreeSePolicy};
+use ostree_sys::*;
 use std::path::PathBuf;
 
 mod repo_checkout_filter;
@@ -50,6 +50,7 @@ type StringStash<'a, T> = Stash<'a, *const c_char, Option<T>>;
 type WrapperStash<'a, GlibT, WrappedT> = Stash<'a, *mut GlibT, Option<WrappedT>>;
 
 impl<'a> ToGlibPtr<'a, *const OstreeRepoCheckoutAtOptions> for RepoCheckoutAtOptions {
+    #[allow(clippy::type_complexity)]
     type Storage = (
         Box<OstreeRepoCheckoutAtOptions>,
         StringStash<'a, PathBuf>,
@@ -90,7 +91,7 @@ impl<'a> ToGlibPtr<'a, *const OstreeRepoCheckoutAtOptions> for RepoCheckoutAtOpt
 
         if let Some(filter) = &self.filter {
             options.filter_user_data = filter.to_glib_none().0;
-            options.filter = repo_checkout_filter::trampoline();
+            options.filter = Some(repo_checkout_filter::filter_trampoline);
         }
 
         Stash(
@@ -112,10 +113,6 @@ mod tests {
     use crate::RepoCheckoutFilterResult;
     use gio::{File, NONE_CANCELLABLE};
     use glib_sys::{GFALSE, GTRUE};
-    use ostree_sys::{
-        OSTREE_REPO_CHECKOUT_MODE_NONE, OSTREE_REPO_CHECKOUT_MODE_USER,
-        OSTREE_REPO_CHECKOUT_OVERWRITE_NONE, OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL,
-    };
     use std::ffi::{CStr, CString};
     use std::ptr;
 
@@ -190,7 +187,7 @@ mod tests {
             );
             assert_eq!((*ptr).unused_ints, [0; 6]);
             assert_eq!((*ptr).unused_ptrs, [ptr::null_mut(); 3]);
-            assert_eq!((*ptr).filter, repo_checkout_filter::trampoline());
+            assert!((*ptr).filter == Some(repo_checkout_filter::filter_trampoline));
             assert_eq!(
                 (*ptr).filter_user_data,
                 options.filter.as_ref().unwrap().to_glib_none().0,
index f83af232fb0498d72669719f9c366abb30536348..44a3a7f36607b9ffc4b301f23776c9a11040bf56 100644 (file)
@@ -1,10 +1,8 @@
 use crate::{Repo, RepoCheckoutFilterResult};
-use glib::translate::{
-    from_glib_borrow, from_glib_none, FromGlibPtrNone, Stash, ToGlib, ToGlibPtr,
-};
+use glib::translate::*;
 use glib_sys::gpointer;
 use libc::c_char;
-use ostree_sys::{OstreeRepo, OstreeRepoCheckoutFilterResult};
+use ostree_sys::*;
 use std::path::{Path, PathBuf};
 
 /// A filter callback to decide which files to checkout from a [Repo](struct.Repo.html). The
@@ -64,7 +62,7 @@ impl FromGlibPtrNone<gpointer> for &RepoCheckoutFilter {
 ///
 /// # Panics
 /// If any parameter is a null pointer, the function panics.
-unsafe extern "C" fn filter_trampoline(
+pub(super) unsafe extern "C" fn filter_trampoline(
     repo: *mut OstreeRepo,
     path: *const c_char,
     stat: *mut libc::stat,
@@ -87,25 +85,9 @@ unsafe extern "C" fn filter_trampoline(
     result.to_glib()
 }
 
-/// Returns the trampoline function in a `Some`.
-///
-/// This is mostly convenient because the full type needs to be written out in fewer places.
-pub(super) fn trampoline() -> Option<
-    unsafe extern "C" fn(
-        *mut OstreeRepo,
-        *const c_char,
-        *mut libc::stat,
-        gpointer,
-    ) -> OstreeRepoCheckoutFilterResult,
-> {
-    Some(filter_trampoline)
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
-    use glib::translate::ToGlibPtr;
-    use ostree_sys::OSTREE_REPO_CHECKOUT_FILTER_SKIP;
     use std::ffi::CString;
     use std::ptr;